package com.request.toyexchange;

/*
 * 用户接收到申请交换玩具的订单
 * 完善之后提交，系统即视为两个用户交换玩具的过程成功
 */

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.bjtu.toyexchange.R;

public class ReceRequest extends Activity {
	private Button fanhui, che_toy1, che_toy2, submit, reject;
	private EditText rece_way;
	private TextView sen_user, rec_user, sen_way;
	private String username1, username2, phone1, phone2;
	
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.rece_req);
		
		//得到自己用户名
		Intent intent = this.getIntent();
		username2 = intent.getStringExtra("username");
		
		//得到发送申请者的用户名
		username1 = intent.getStringExtra("sender");
		
		//设置在自己用户名textview为用户名
		rec_user = (TextView)ReceRequest.this.findViewById(R.id.rece_rece_username);
		rec_user.setText(username2);
		
		//得到并设置对方用户名、手机号
		phone1 = "13810414402";
		sen_user = (TextView)ReceRequest.this.findViewById(R.id.rece_sen_username);
		sen_user.setText(username1);
		sen_way = (TextView)ReceRequest.this.findViewById(R.id.rece_send_way);
		sen_way.setText(phone1);
		
		//查看对方玩具的按钮
		che_toy1 = (Button)findViewById(R.id.rece_che_toy);
		che_toy1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent int2 = new Intent();
				int2.putExtra("username", username1);
				int2.setClass(ReceRequest.this, CheckToyActivity.class);
				ReceRequest.this.startActivity(int2);
			}
		});
		
		//查看自己玩具的按钮
		che_toy2 = (Button)findViewById(R.id.rece_che_toy2);
		che_toy2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent int2 = new Intent();
				int2.putExtra("username", username2);
				int2.setClass(ReceRequest.this, CheckToyActivity.class);
				ReceRequest.this.startActivity(int2);
			}
		});
		
		//确认申请的按钮
		submit = (Button)findViewById(R.id.rece_sub_btn);
		submit.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				//得到自己用户输入的手机号码
				rece_way = (EditText)ReceRequest.this.findViewById(R.id.rece_rece_way);
				phone2 = rece_way.getText().toString();
				
				//手机号码信息校验
				if (("").equals(phone2) || null == phone2) {
					Toast.makeText(ReceRequest.this, "联系方式不能为空...",100).show();
					return;
				}
				else if (phone2.length() != 11) {
					Toast.makeText(ReceRequest.this,"请输入正确的手机号码...",100).show();
					return;
				}
				else {
					Toast.makeText(ReceRequest.this, "玩具交换成功...", 200).show();
					ReceRequest.this.finish();
				}
			}
		});
		
		//拒绝申请的按钮
		reject = (Button)findViewById(R.id.rece_rej_btn);
		reject.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Toast.makeText(ReceRequest.this, "拒绝申请...", 200).show();
			}
		});
		
		//返回的按钮
		fanhui = (Button)findViewById(R.id.recreqback);
		fanhui.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				ReceRequest.this.finish();
			}
		});
	}
}
